package com.snopy.concurrency.atomic;

import com.snopy.pojo.Banana;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * @author snopy
 * @version 1.0.0
 * @classname FiledDemo
 * @description
 * @email 77912204@qq.com
 * @date 2022/06/28 17:36
 */
@Slf4j
public class FiledDemo {
    static Banana banana = new Banana();
    static AtomicReferenceFieldUpdater<Banana, String> arfu = AtomicReferenceFieldUpdater.newUpdater(Banana.class,
            String.class,"name");
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
           log.debug("change result:{}",arfu.compareAndSet(banana,null,"香蕉"));
        },"t1");
        t1.start();
        t1.join();
        log.info(banana.toString());
    }
}
